define(['jquery', 'jquerymobile', 'net', 'dialogs','activity_register','videoDetailed','filter','questionnaires','survey_questionnaires','survey_confirm','panle'], function($, m, net, dia, activityRegister,videodetail,fl,questionnaires,surveyQuestionnaires,surveyConfirm,panle) {
    // Nick added for pull to refresh start
    var isScrolling = false,
        showeye = "false",
        iScroll_news = {
            myScroll: null,
            allowGetMore: true,
            pullDownAction: function() {
                getNews(true);
            },
            pullUpAction: function() {
                getNews();
            },
            loaded: function(wrapper) {
                var $wrapper = $("#" + wrapper),
                    $pullDownEl = $wrapper.find("#pullDown"),
                    $pullDownLabel = $pullDownEl.find(".pullDownLabel"),
                    pullDownOffset = $pullDownEl[0].offsetHeight,
                    $pullUpEl = $wrapper.find("#pullUp"),
                    $pullUpLabel = $pullUpEl.find(".pullUpLabel"),
                    $pullUpIcon = $pullUpEl.find(".pullUpIcon"),
                    pullUpOffset = $pullUpEl[0].offsetHeight;

                iScroll_news.myScroll = new iScroll(wrapper, {
                    hScrollbar: false,
                    vScrollbar: false,
                    useTransition:false,
                    checkDOMChanges:false,
                    topOffset: pullDownOffset,
                    onRefresh: function () {
                        console.log("onRefresh");
                        if ($pullDownEl.hasClass("loading")) {
                            $pullDownEl.removeClass("loading");
                            $pullDownLabel.text("Pull down to refresh...");
                        } else if ($pullUpEl.hasClass("loading")) {
                            $pullUpEl.removeClass("loading");
                            if (iScroll_news.allowGetMore) {
                                $pullUpIcon.show();
                                $pullUpLabel.text("Pull up to load more...");
                            } else {
                                $pullUpIcon.hide();
                                $pullUpLabel.text("No more articles available!");
                            }
                        }
                    },
                    onScrollMove: function () {
                        if(this.y >= -50){
                            $('div[id=newsroom_top]').fadeOut();
                        }
                        else{
                            $('div[id=newsroom_top]').fadeIn();
                        }
                        if (this.y > 5 && !$pullDownEl.hasClass("flip")) {
                            $pullDownEl.addClass("flip");
                            $pullDownLabel.text("Release to refresh...");
                            this.minScrollY = 0;
                            $pullDownEl.css("margin-top","10px");
                        } else if (this.y < 5 && $pullDownEl.hasClass("flip")) {
                            $pullDownEl.removeClass("flip");
                            $pullDownLabel.text("Pull down to refresh...");
                            $pullDownEl.css("margin-top","0px");
                            this.minScrollY = -pullDownOffset;
                        } else if (this.y < (this.maxScrollY - 5) && !$pullUpEl.hasClass("flip")) {
                            if (iScroll_news.allowGetMore) {
                                $pullUpEl.addClass("flip");
                                $pullUpLabel.text("Release to refresh...");
                                this.maxScrollY = this.maxScrollY;
                            }
                        } else if (this.y > (this.maxScrollY + 5) && $pullUpEl.hasClass("flip")) {
                            if (iScroll_news.allowGetMore) {
                                $pullUpEl.removeClass("flip");
                                $pullUpLabel.text("Pull up to load more...");
                                this.maxScrollY = pullUpOffset;
                            }
                        }
                        isScrolling = true;
                    },
                    onScrollEnd: function () {
                        console.log("onScrollEnd"+this.y);
                        if(this.y >= -50){
                            $('div[id=newsroom_top]').fadeOut();
                        }
                        else{
                            $('div[id=newsroom_top]').fadeIn();
                        }
                        if ($pullDownEl.hasClass("flip")) {
                            $pullDownEl.attr("class", "loading");
                            $pullDownLabel.text("Loading...");
                            iScroll_news.pullDownAction();
                            $pullDownEl.css("margin-top","10px");
                        } else if ($pullUpEl.hasClass("flip")) {
                            if (iScroll_news.allowGetMore) {
                                iScroll_news.allowGetMore = false;
                                $pullUpEl.attr("class", "loading");
                                $pullUpLabel.text("Loading...");
                                iScroll_news.pullUpAction();
                            }
                        }
                        else{
                            $pullDownEl.css("margin-top","0px");
                        }
                        setTimeout(function() {
                            isScrolling = false;
                        }, 500);
                    }
                });
            }
        };
    // Nick added for pull to refresh end
    // 查询到的新闻数据
    var v_news = [];

    // 当前页数
    var currentPageNumer = 1;

    // 控制底部事件激发开关 0表示开 非0表示关闭时间
    var scrollButtomOn = 0;

    // 上一次滚动的位置
    var scrollTopBefore = 0;

    // 补充0
    function pad(n, width, z) {
        z = z || '0';
        n = n + '';
        return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
    }

    /**
     * 展示过滤按钮样子
     */
    function displayFilter() {
        var filterSize = $("#newsFilter_ul li").size();
        if(filterSize > 0){
            filterSize = parseInt(filterSize);
        } 
        else{
            filterSize = 0;
        }
        if ((!$.isEmptyObject(localStorage['selected_tags'])) &&
            (localStorage['selected_tags'].toString().split(',').length < filterSize)) {
            $('#newsroom_btn_filter').removeClass('filter').addClass('filterOn');
        } else {
            $('#newsroom_btn_filter').removeClass('filterOn').addClass('filter');
        }

    }

    /**
     * 禁用滚动时间3秒
     */
    function disableScrollBottom() {
        scrollButtomOn = 3;
        var timer = setInterval(function() {
            if (scrollButtomOn == 0) {
                clearInterval(timer);
                return;
            }

            scrollButtomOn--;

        }, 1000);
    }

    function TagtoLit(tag) {
        if (tag == 'Center Operations')
            return 'OPS';
        else if (tag == 'Technical Development')
            return 'TD';
        else if (tag == 'Q&P')
            return 'Q&P';
        else if (tag == 'Human Resources')
            return 'HR';
        else if (tag == 'Trade Union')
            return 'GTU';
        else if (tag == 'Finance')
            return 'FIN';
        else if (tag == 'Corporate Sustainability')
            return 'CS';
        else if (tag == 'Communications')
            return 'COMMS';
        else if (tag == 'Talent Show')
            return 'TS';
        else if (tag == 'NOW')
            return 'NOW';
        else if (tag == '#red')
            return '#red';
        else if (tag == 'GSC')
            return 'GSC';
        else {
            console.assert(false, '标签 %o 不存在 ', tag );
        }
    }

    //创建活动
    function creatActivity(banner, subject, brifContent, time, day, venue,deadlineTime, tags, eye, prise, like, id,videoFlag) {
        console.assert(subject != null, '活动标题 %o 不能为空', subject);
        console.assert(brifContent != null, '活动简介 %o 不能为空', brifContent);
        console.assert(time != null, '活动时间 %o 不能为空', time);
        console.assert(day != null, '活动日期 %o 不能为空', day);
        console.assert(venue != null, '活动地点 %o 不能为空', venue);
        console.assert(tags != null, '活动标签 %o 不能为空', tags);
        var activityBrifContent = brifContent;
        //超过160的字符就显示...
        if (activityBrifContent.length > 160) {
            activityBrifContent = brifContent.substring(0, 160) + '...';
        }

        var html_tags = '';
        if(tags != null) {
            $.each(tags, function(index, val) {
                if (val.name == 'Communications')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(77, 134, 176);">COMMS</span>  ';
                if (val.name == 'Corporate Sustainability')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(137, 217, 78);">CS</span>  ';
                if (val.name == 'Finance')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(219, 218, 0);">FIN</span>  ';
                if (val.name == 'Trade Union')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(147, 182, 164);">GTU</span>  ';
                if (val.name == 'Human Resources')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(230, 170, 0);">HR</span>  ';
                if (val.name == 'Q&P')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(76, 176, 170);">Q&P</span>  ';
                if (val.name == 'Center Operations')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(138, 116, 122);">OPS</span>  ';
                if (val.name == 'Technical Development')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(121, 110, 172);">TD</span>  ';
                if (val.name == 'Talent Show')
                    html_tags += '\<span class="spanTag" style="background-color: #a3bdad;">TALENT SHOW</span>  ';
                if (val.name == 'NOW')
                    html_tags += '\<span class="spanTag" style="background-color: #db0011;">NOW</span>  ';
                if (val.name == '#red')
                    html_tags += '\<span class="spanTag" style="background-color: #f26647;">#red</span>  ';
                if (val.name == 'GSC')
                    html_tags += '\<span class="spanTag" style="background-color: #e6b012;">GSC</span>  ';
            });
        }

        var likeAttr = (like==true) ? 'yes' :'no';
        var likeit = "no";
        var eyehtml = "";
        if(showeye == "true"){
            eyehtml ='\<span style="margin-left:10px "><i class="eyeicon"></i><span class="eye_pagetag" >'+eye+'\</span></span>';
        }
        var imgHtml = '\<div style="width: 100%" ><img src="'+banner+'"\ style="width: 100%" alt=""/></div>';
        if(videoFlag  == "video"){
            imgHtml = '\<div style="width: 100%;position:relative;"><i class="videotag_icon"></i><img src="'+banner+'"\ style="width: 100%;"  alt=""/>\ </div>';
        }
        var html = '\<li style="border: 0px;padding: 0px;margin-bottom:10px" like="'+likeAttr+'" id="'+id+'"\>\
            <div id="newsroom_detail_sele">'+imgHtml+'\<label style="margin: 10px; font-size: 18px; white-space:normal;color: #404040;word-break: break-word;">'+ subject +'\</label>\
                <div style="margin: 10px">\
                    <div style="white-space:normal;font-weight: normal;font-size: 12px;color: #404040;word-break: break-word;">'+ activityBrifContent.replace(/\n/g,'</br>') +'\</div>\
                </div>\
                <div style="margin: 10px;font-size: 11px;color: #404040;">\
                    <span style="display: block;white-space: normal;">'+ time +'\</span>\
                    <span style="display: block;white-space: normal;">'+ day +'\</span>\
                    <span style="display: block;white-space: normal;">'+ venue +'\</span>\
                    <span style="display: block;white-space: normal;">'+ deadlineTime +'\</span>\
                </div>\
                <div id="newsroom_detail_sele_tags" style="margin-left: 10px; width: auto; white-space: normal; margin-bottom: 10px; height: auto; overflow: hidden;">\
                    '+ html_tags +'\<span style="float: right; font-size: 10px; color: #808080; margin-right: 15px; margin-top: 10px; padding: 3px;">'+eyehtml+'\<span style="margin-left:10px; ">\
            <i class="'+((likeit == "no")?"index_prise_no prise":"index_prise prise")+'"\></i><span class="prise_pagetag">'+prise+'\</span></span></span>\
            </div><div style="border-bottom: solid 1px;border-bottom-color: #C0C0C0;width: 100%;clear:left;"></div>\
            </div>\
            <div id="newsroom_nowRegister" class="li_nowRegister"  style="margin: 10px 0px 10px 10px;width: auto;height: 28px;line-height: 28px;">\
                <div style="padding: 0px;">\
                    <span style="width: 90%;float: left;font-size:14px">Register now</span>\
                    <span class="right_chevron" style="width: 10%;float: right;height: 25px"></span>\
                </div>\
            </div>\
            </li>';
        return html;
    }

    //创建survey

    function creatSurvey(banner, subject, dTime,brifContent, tags, eye, prise, like, id,videoFlag) {
        var activityBrifContent = brifContent;
        //超过160的字符就显示...
        if (activityBrifContent.length > 160) {
            activityBrifContent = brifContent.substring(0, 160) + '...';
        }

        var html_tags = '';
        if(tags != null) {
            $.each(tags, function(index, val) {
                if (val.name == 'Communications')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(77, 134, 176);">COMMS</span>  ';
                if (val.name == 'Corporate Sustainability')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(137, 217, 78);">CS</span>  ';
                if (val.name == 'Finance')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(219, 218, 0);">FIN</span>  ';
                if (val.name == 'Trade Union')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(147, 182, 164);">GTU</span>  ';
                if (val.name == 'Human Resources')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(230, 170, 0);">HR</span>  ';
                if (val.name == 'Q&P')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(76, 176, 170);">Q&P</span>  ';
                if (val.name == 'Center Operations')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(138, 116, 122);">OPS</span>  ';
                if (val.name == 'Technical Development')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(121, 110, 172);">TD</span>  ';
                if (val.name == 'Talent Show')
                    html_tags += '\<span class="spanTag" style="background-color: #a3bdad;">TALENT SHOW</span>  ';
                if (val.name == 'NOW')
                    html_tags += '\<span class="spanTag" style="background-color: #db0011;">NOW</span>  ';
                if (val.name == '#red')
                    html_tags += '\<span class="spanTag" style="background-color: #f26647;">#red</span>  ';
                if (val.name == 'GSC')
                    html_tags += '\<span class="spanTag" style="background-color: #e6b012;">GSC</span>  ';
            });
        }

        var likeAttr = (like==true) ? 'yes' :'no';
        var likeit = "no";
        var eyehtml = "";
        if(showeye == "true"){
            eyehtml ='\<span style="margin-left:10px "><i class="eyeicon"></i><span class="eye_pagetag" >'+eye+'\</span></span>';
        }
        var imgHtml = '\<div style="width: 100%" ><img src="'+banner+'"\ style="width: 100%" alt=""/></div>';
        if(videoFlag  == "video"){
            imgHtml = '\<div style="width: 100%;position:relative;"><i class="videotag_icon"></i><img src="'+banner+'"\ style="width: 100%;"  alt=""/>\ </div>';
        }
        var html = '\<li style="border: 0px;padding: 0px;margin-bottom:10px" like="'+likeAttr+'" id="'+id+'"\>\
            <div id="newsroom_detail_survey">'+imgHtml+'\<label style="margin: 10px; font-size: 18px; white-space:normal;color: #404040;word-break: break-word;">'+ subject +'\</label>\
                <div style="margin: 10px">\
                    <div style="white-space:normal;font-weight: normal;font-size: 12px;color: #404040;word-break: break-word;">'+ activityBrifContent.replace(/\n/g,'</br>') +'\</div>\
                </div>\
                <div style="display:block;color:#404040;margin:10px;font-size:11px;white-space: normal">'+dTime+'\</div>\
                <div id="newsroom_detail_survey_tags" style="margin-left: 10px; width: auto; white-space: normal; margin-bottom: 10px; height: auto; overflow: hidden;">\
                    '+ html_tags +'\<span style="float: right; font-size: 10px; color: #808080; margin-right: 15px; margin-top: 10px; padding: 3px;">'+eyehtml+'\<span style="margin-left:10px; ">\
            <i class="'+((likeit == "no")?"index_prise_no prise":"index_prise prise")+'"\></i><span class="prise_pagetag">'+prise+'\</span></span></span>\
            </div><div style="border-bottom: solid 1px;border-bottom-color: #C0C0C0;width: 100%;clear:left;"></div>\
            </div>\
            <div id="newsroom_nowSurvey" class="li_nowSurvey"  style="margin: 10px 0px 10px 10px;width: auto;height: 28px;line-height: 28px;">\
                <div style="padding: 0px;">\
                    <span style="width: 90%;float: left;font-size:14px">Respond now</span>\
                    <span class="right_chevron" style="width: 10%;float: right;height: 25px"></span>\
                </div>\
            </div>\
            </li>';
        return html;
    }
    /**
     * 展示内容
     * @param content
     */
    function showContent(contentList, refresh) {
        var contentHTML = "",
            contentArray = [],
            $newsroom_listview = $("#newsroom_listview_news");
        $.each(contentList, function(i, content) {
            console.assert(content.types != null, '要展示的内容都没有类型啊');

            if (content.types == 'new') {
                if (content.type == 'news') {
                contentArray.push(getNewsHTML(content));
                }
                else if (content.type == 'video') {
                    contentArray.push(getVideoHTML(content));
                }
            } else if (content.types == 'activity') {
                contentArray.push(getAcitvityHTML(content));
            }
            else if (content.types == 'survey') {
                contentArray.push(getSurveyHTML(content));
            }
            else {
                console.assert(false, '除了新闻和活动，目前不会有%s类型。', content.types);
            }
        });
        contentHTML = contentArray.join("");
        if (refresh) {
            $newsroom_listview.html(contentHTML);
        } else {
            $newsroom_listview.append(contentHTML);
        }
        $newsroom_listview.listview("refresh");
    }
    // Nick added for pull to refresh end

    /**
     * 获得新闻HTML
     * @param news
     */
    function getNewsHTML(news) {
        news.TTagses.sort(function(a, b) {

            if (TagtoLit(a.name) > TagtoLit(b.name))
                return 1;
            else if (TagtoLit(a.name) < TagtoLit(b.name))
                return -1;

            return 0;
        });

        var date = new Date(news.approvalTime * 1000);
        var month = getMonthString(date.getMonth());
        var time = 'Posted on ' + date.getDate() + " " + month + " " + date.getFullYear();
        var eye = news.allBrowseTimes ? news.allBrowseTimes : 0;
        var like = news.like;
        var prise = news.likeAmount ? news.likeAmount : 0;
        var li = createNews(news.pic, news.title, news.briefContent, time, news.TTagses,eye,prise,like,news.newsId,news.videoFlag);
        // Nick removed for pull to refresh start
        // $('#newsroom_listview_news').append(li);
        // $('#newsroom_listview_news').listview( "refresh" );
        // Nick removed for pull to refresh end
        // Nick added for pull to refresh start
        return li;
        // Nick added for pull to refresh end
    }
    /**
     * 获得视频HTML
     * @param news
     */
    function getVideoHTML(video) {
        video.TTagses.sort(function(a, b) {

            if (TagtoLit(a.name) > TagtoLit(b.name))
                return 1;
            else if (TagtoLit(a.name) < TagtoLit(b.name))
                return -1;

            return 0;
        });
        var li = createVideo(video);
        return li;
    }
    function createVideo(video) {
        var videoimg = video.pic;
        var title = video.title;
        var briefContent = video.briefContent;
        var tags = video.TTagses;
        var eye = video.allBrowseTimes ? video.allBrowseTimes : 0;
        var like = video.like;
        var prise = video.likeAmount ? video.likeAmount : 0;
        var approvalTime = video.approvalTime;
        var videoFlag = video.videoFlag;
        var date = new Date(approvalTime * 1000);
        var month = getMonthString(date.getMonth());
        var time = 'Posted on ' + date.getDate() + " " + month + " " + date.getFullYear(); 
        if (briefContent.length > 160){
            briefContent = briefContent.substring(0, 160) + '...';
        }
        var html_tags = getTags(tags);
        if (html_tags.length == 0) {
            html_tags = '\<span style="height: 35px;"> &nbsp;</span>';
        }
        var likeAttr = (video.like==true) ? 'yes' :'no';
        var likeit = "no";
        var eyehtml = "";
        if(showeye == "true"){
            eyehtml ='\<span style="margin-left:10px "><i class="eyeicon"></i><span class="eye_pagetag" >'+eye+'\</span></span>';
        }
        var imgHtml = '\<div style="width: 100%" ><img src="'+videoimg+'"\ style="width: 100%" alt=""/></div>';
        if(videoFlag  == "video"){
            imgHtml = '\<div style="width: 100%;position:relative;"><i class="videotag_icon"></i><img src="'+videoimg+'"\ style="width: 100%;"  alt=""/>\ </div>';
        }
        var html = '\<li  style="border: 0px;padding: 0px;margin-bottom:10px" like="'+likeAttr+'" id="'+video.newsId+'"\>' +
            imgHtml+'\<label style="margin: 10px; font-size: 18px; white-space:normal;color: #404040;word-break: break-word;">'+title+'\</label>\
            <div style="margin: 10px">\
                <div style="white-space:normal;font-weight: normal;font-size: 12px;color: #404040;word-break: break-word;">'+briefContent.replace(/\n/g,'</br>')+'\</div>\
            </div>\
            <div style="margin: 0px 10px 0px 10px; height: 40px; line-height: 40px;">\
                <span style="font-size: 10px;color: #808080;white-space: normal;">'+time+'\</span>\
            \<div style="float:right;font-size: 10px;color: #808080;">'+eyehtml+'\<span style="margin-left:10px; ">\
            <i class="'+((likeit == "no")?"index_prise_no prise":"index_prise prise")+'"\></i><span class="prise_pagetag">'+prise+'\</span></span></div>\
            </div><div style="border-bottom: solid 1px;border-bottom-color: #C0C0C0;width: 100%;"></div>\
            <div style="margin-left: 10px; width: auto;white-space: normal;">\
            '+html_tags+'\
            \</div>\
            <div style="clear:left; width: 100%;height:10px;"></div>\
        </li>';
        return html; 
    }
    /**
     * 获得活动HTML
     * @param activity
     */
    function getAcitvityHTML(activity) {
        activity.tags.sort(function(a, b) {

            if (TagtoLit(a.name) > TagtoLit(b.name))
                return 1;
            else if (TagtoLit(a.name) < TagtoLit(b.name))
                return -1;

            return 0;
        });

        var startDate = new Date(activity.startTime * 1000);
        var endDate = new Date(activity.endTime * 1000);
        var deadline = new Date(activity.deadline * 1000);
        var startTime = 'Start: ' + pad(startDate.getHours(), 2) + ':' + pad(startDate.getMinutes(),2) + ', ' + startDate.getDate() + " " + getMonthString(startDate.getMonth()) + " " + startDate.getFullYear();
        var endTime = 'End: ' + pad(endDate.getHours(),2) + ':' + pad(endDate.getMinutes(),2) + ', ' + endDate.getDate() + " " + getMonthString(endDate.getMonth()) + " " + endDate.getFullYear();
        var venue = 'Venue: ' + activity.venue;
        var deadlineTime = 'Deadline: ' + pad(deadline.getHours(),2) + ':' + pad(deadline.getMinutes(),2) + ', ' + deadline.getDate() + " " + getMonthString(deadline.getMonth()) + " " + deadline.getFullYear();

        var eye = activity.allBrowseTimes ? activity.allBrowseTimes : 0;
        var like = activity.like;
        var prise = activity.likeAmount ? activity.likeAmount : 0;
        var li = creatActivity(activity.banner, activity.subject, activity.briefContent,startTime ,endTime , venue,deadlineTime, activity.tags,eye,prise,like,activity.id,activity.videoFlag);
        // Nick removed for pull to refresh start
        // $('#newsroom_listview_news').append(li);
        // $('#newsroom_listview_news').listview("refresh");
        // Nick removed for pull to refresh end
        // Nick added for pull to refresh start
        return li;
        // Nick added for pull to refresh end
    }

    /**
     *
     * @param month
     * @returns {string}
     */
    function getSurveyHTML(survey) {
        survey.tags.sort(function(a, b) {

            if (TagtoLit(a.name) > TagtoLit(b.name))
                return 1;
            else if (TagtoLit(a.name) < TagtoLit(b.name))
                return -1;

            return 0;
        });
        var deadlineDate = new Date(survey.deadline * 1000);
        var dTime = 'Deadline: '+pad(deadlineDate.getHours(),2)+':'+pad(deadlineDate.getMinutes(),2)+', '+deadlineDate.getDate()+" "+getMonthString(deadlineDate.getMonth())+" "+deadlineDate.getFullYear();
        var eye = survey.allBrowseTimes ? survey.allBrowseTimes : 0;
        var like = survey.like;
        var prise = survey.likeAmount ? survey.likeAmount : 0;

        var li = creatSurvey(survey.banner, survey.subject, dTime,survey.briefContent,survey.tags,eye,prise,like,survey.survey_id,survey.videoFlag);
        // Nick removed for pull to refresh start
        // $('#newsroom_listview_news').append(li);
        // $('#newsroom_listview_news').listview("refresh");
        // Nick removed for pull to refresh end
        // Nick added for pull to refresh start
        return li;
        // Nick added for pull to refresh end
    }

    function getMonthString(month) {
        month = month + 1;
        if (month == 1)
            return 'Jan';
        else if (month == 2)
            return 'Feb';
        else if (month == 3)
            return 'Mar';
        else if (month == 4)
            return 'Apr';
        else if (month == 5)
            return 'May';
        else if (month == 6)
            return 'June';
        else if (month == 7)
            return 'July';
        else if (month == 8)
            return 'Aug';
        else if (month == 9)
            return 'Sept';
        else if (month == 10)
            return 'Oct';
        else if (month == 11)
            return 'Nov';
        else if (month == 12)
            return 'Dec';
        else {
            console.assert(false, '月份 %o 不存在 ', month );
        }
    }
    function getTags(tags){
        var html_tags = "";
        if (tags != null) {
            $.each(tags, function(index, val) {
                if (val.name == 'Communications')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(77, 134, 176);">COMMS</span>  ';
                if (val.name == 'Corporate Sustainability')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(137, 217, 78);">CS</span>  ';
                if (val.name == 'Finance')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(219, 218, 0);">FIN</span>  ';
                if (val.name == 'Trade Union')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(147, 182, 164);">GTU</span>  ';
                if (val.name == 'Human Resources')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(230, 170, 0);">HR</span>  ';
                if (val.name == 'Q&P')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(76, 176, 170);">Q&P</span>  ';
                if (val.name == 'Center Operations')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(138, 116, 122);">OPS</span>  ';
                if (val.name == 'Technical Development')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(121, 110, 172);">TD</span>  ';
                if (val.name == 'Talent Show')
                    html_tags += '\<span class="spanTag" style="background-color: #a3bdad;">TALENT SHOW</span>  ';
                if (val.name == 'NOW')
                    html_tags += '\<span class="spanTag" style="background-color: #db0011;">NOW</span>  ';
                if (val.name == '#red')
                    html_tags += '\<span class="spanTag" style="background-color: #f26647;">#red</span>  ';
                if (val.name == 'GSC')
                    html_tags += '\<span class="spanTag" style="background-color: #e6b012;">GSC</span>  ';
            });
        }
        return html_tags;


    }
    // 获得新闻 
    function getNews(refresh,pageStatus) {
        if(pageStatus){
            pageInitShow();
            tagInitShow();
        }
        if (refresh) {
            currentPageNumer = 1;
            v_news = [];
        }
        // Nick added for pull to refresh end
        var postData = {};
        postData['pager.pageNo'] = currentPageNumer;
        postData['pager.pageSize'] = 5;
        postData['userId'] = q['user'].userId; 
        var filterSize = $("#newsFilter_ul li").size();
        if(filterSize > 0){
            filterSize = parseInt(filterSize);
        }  
        else{
            filterSize = 0;
        }
        console.log(filterSize);
        if ((!$.isEmptyObject(localStorage['selected_tags'])) &&
            (localStorage['selected_tags'].toString().split(',').length > 0) &&
            (localStorage['selected_tags'].toString().split(',').length < filterSize)) {
            postData['tagNames'] = localStorage['selected_tags'].toString().substr(0, (localStorage['selected_tags'].length - 1));
        }
        // 获取新闻 
        var command = "news/listNewsActivitys";  
        if($("#newsroom").hasClass("activities")){ 
            command = "activity/show";
        } 
        else{  
            if ((!$.isEmptyObject($('#newsroom_header_searchbar')))
                && (!$.isEmptyObject($('#newsroom_header_searchbar').val()))){
                postData['keyword'] = $('#newsroom_header_searchbar').val();
            }
            if($("#newsroom").hasClass("talentShow")){
                postData['tagNames'] = "Talent Show";
            }
            else if($("#newsroom").hasClass("video")){
                postData['type'] = "hbcnNow";
            }
            else if($("#newsroom").hasClass("newsroom")){
                postData['type'] = "newsroom";
            }
        }   

        net.post(command, postData, function(error){
        }, function(response){ 
            if (response.code != 0) {

            } else { 
                var newsList = response.data.news;
                if($("#newsroom").hasClass("activities")){ 
                    newsList = response.data.activity;
                }
                newsListLength = newsList.length;
                if (newsListLength > 0) {
                    v_news = v_news.concat(newsList);
                    showContent(newsList, refresh);
                    // Nick added for pull to refresh end

                    currentPageNumer++;
                }else{
                    if(refresh){
                        $("#newsroom_listview_news").html("");
                    }else{
                        $("#newsroom_listview_news").append("");
                    }
                }
                if (iScroll_news.myScroll == null) {
                    iScroll_news.loaded("news_wrapper");
                }
                // Nick added for pull to refresh start
                var $pullUpEl = $("#news_wrapper").find("#pullUp"),
                    $pullUpLabel = $pullUpEl.find(".pullUpLabel"),
                    $pullUpIcon = $pullUpEl.find(".pullUpIcon");
                if (refresh) {
                    if(newsListLength == 1){
                        $pullUpIcon.hide();
                        $pullUpLabel.text("No more articles available!");
                    }else if(newsListLength == 0){
                        $pullUpIcon.hide();
                        $pullUpEl.hide();
                    }else{
                        $pullUpLabel.text("Pull up to load more...");
                        $pullUpIcon.show();
                        $pullUpEl.show();
                    }
                    if (iScroll_news.myScroll && iScroll_news.myScroll.y !== 0) {
                        iScroll_news.myScroll.y = 0;
                    }
                }
                if (newsListLength < 1) {
                    iScroll_news.allowGetMore = false;
                } else {
                    iScroll_news.allowGetMore = true;
                }
                setTimeout(function() {
                    if(iScroll_news.myScroll){
                    iScroll_news.myScroll.refresh();
                    }
                    if(newsListLength == 0){
                        $pullUpEl.show();
                        $pullUpIcon.hide();
                        $pullUpLabel.text("No more articles available!");
                    }
                    disableClickEvent(false);
                }, 800);
                window.shouldPageRefresh.newsroom = false; 
            }
        },{loading:false});
    }

    // 创建新闻
    function createNews(img, title, content, timestamp, tags,eye,prise,like,id,videoFlag) {
        console.assert(img != null, '新闻图片不能为空：%o', img);
        console.assert(title != null, '新闻标题不能为空：%o', title);
        console.assert(content != null, '新闻内容简介不能为空：%o', content);
        console.assert(timestamp != null, '新闻发布时间不能为空：%o', timestamp);
        console.assert(tags != null, '新闻标签不能为空：%o', tags);
        var newContent = content; 
        if (newContent.length > 160)
            newContent = content.substring(0, 160) + '...';


        var html_tags = '';

        if (tags != null) {
            $.each(tags, function(index, val) {
                if (val.name == 'Communications')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(77, 134, 176);">COMMS</span>  ';
                if (val.name == 'Corporate Sustainability')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(137, 217, 78);">CS</span>  ';
                if (val.name == 'Finance')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(219, 218, 0);">FIN</span>  ';
                if (val.name == 'Trade Union')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(147, 182, 164);">GTU</span>  ';
                if (val.name == 'Human Resources')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(230, 170, 0);">HR</span>  ';
                if (val.name == 'Q&P')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(76, 176, 170);">Q&P</span>  ';
                if (val.name == 'Center Operations')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(138, 116, 122);">OPS</span>  ';
                if (val.name == 'Technical Development')
                    html_tags += '\<span class="spanTag" style="background-color: rgb(121, 110, 172);">TD</span>  ';
                 if (val.name == 'Talent Show')
                    html_tags += '\<span class="spanTag" style="background-color: #a3bdad;">TALENT SHOW</span>  ';
                 if (val.name == 'NOW')
                    html_tags += '\<span class="spanTag" style="background-color: #db0011;">NOW</span>  ';
                if (val.name == '#red')
                    html_tags += '\<span class="spanTag" style="background-color: #f26647;">#red</span>  ';
                if (val.name == 'GSC')
                    html_tags += '\<span class="spanTag" style="background-color: #e6b012;">GSC</span>  ';
            });
        }

        if (html_tags.length == 0) {
            html_tags = '\<span style="height: 35px;"> &nbsp; </span>';
        }
        var likeAttr = (like==true) ? 'yes' :'no';
        var likeit = "no";
        var eyehtml = "";
        if(showeye == "true"){
            eyehtml ='\<span style="margin-left:10px "><i class="eyeicon"></i><span class="eye_pagetag" >'+eye+'\</span></span>';
        }
        var imgHtml = '\<div style="width: 100%" ><img src="'+img+'"\ style="width: 100%" alt=""/></div>';
        if(videoFlag  == "video"){
            imgHtml = '\<div style="width: 100%;position:relative;"><i class="videotag_icon"></i><img src="'+img+'"\ style="width: 100%;"  alt=""/>\ </div>';
        }
        var html = '\<li  style="border: 0px;padding: 0px;margin-bottom:10px" like="'+likeAttr+'" id="'+id+'"\>' +
            imgHtml+'\<label style="margin: 10px; font-size: 18px; white-space:normal;color: #404040;word-break: break-word;">'+title+'\</label>\
            <div style="margin: 10px">\
                <div style="white-space:normal;font-weight: normal;font-size: 12px;color: #404040;word-break: break-word;">'+newContent.replace(/\n/g,'</br>')+'\</div>\
            </div>\
            <div style="margin: 0px 10px 0px 10px; height: 40px; line-height: 40px;">\
                <span style="font-size: 10px;color: #808080;white-space: normal;">'+timestamp+'\</span>\
            \<div style="float:right;font-size: 10px;color: #808080;">'+eyehtml+'\<span style="margin-left:10px; ">\
            <i class="'+((likeit == "no")?"index_prise_no prise":"index_prise prise")+'"\></i><span class="prise_pagetag">'+prise+'\</span></span></div></div>\
            <div style="border-bottom: solid 1px;border-bottom-color: #C0C0C0;width: 100%;"></div>\
            <div style="margin-left: 10px; width: auto;white-space: normal;">\
            '+html_tags+'\
            \</div>\
            <div style="clear:left; width: 100%;height:10px;"></div>\
        </li>';

        return html;
    }
    //推出Tilter页面
    $('#newsroom_btn_filter').on('click',function() {
        if($("#filter_btn_applay").attr("filterResourcePage") == "video"){
            localStorage['selected_tags']='';
        }
        $('#filter_btn_applay').attr("filterResourcePage",'newsroom');
        $('#filter_btn_applay').attr("filterResourceWrapper",'news_wrapper');
        $.mobile.newChangePage("#filter",{ transition: "slide",reverse: false,changeHash: false});
    });
    // 点击某一个新闻
    $('#newsroom_listview_news').on('click', 'li', function(evt) { 
        if (isScrolling) return false; 
        window.disableTouch = true;
        if (v_news[$(this).index()].types == 'new') {
            v_news[$(this).index()].showeye = showeye;
            toDetailPage(v_news[$(this).index()]);
        }
    }).on('click', '#newsroom_detail_sele', function(evt) {
        if (isScrolling) return false; 
        var $li_nowRegister = $("#newsroom li#"+v_news[$(this).parent().index()].id+" .li_nowRegister");
        if($li_nowRegister.hasClass("registered")){
            v_news[$(this).parent().index()]['flag'] = true;
            v_news[$(this).parent().index()]['enrollStatus'] = v_news[$(this).parent().index()]['joinType'];
            if($li_nowRegister.hasClass("calendarAdded")){
                v_news[$(this).parent().index()]['isSetReminder'] = "Y";
                $li_nowRegister.removeClass("calendarAdded");
            }
            $li_nowRegister.removeClass("registered");
        }
        v_news[$(this).parent().index()].showeye = showeye; 
        toDetailPage(v_news[$(this).parent().index()]);
    }).on('click', '#newsroom_detail_survey', function(evt) {
        if (isScrolling) return false; 
        if($("li#"+v_news[$(this).parent().index()].survey_id+" .li_nowSurvey").hasClass("registered")){
            v_news[$(this).parent().index()].regFlag = "true";
            $("li#"+v_news[$(this).parent().index()].survey_id+" .li_nowSurvey").removeClass("registered");
        }  
        v_news[$(this).parent().index()].showeye = showeye;
        v_news[$(this).parent().index()].frompage = "#newsroom";
        toDetailPage(v_news[$(this).parent().index()]);
    }).on('click', '#newsroom_nowRegister', function(evt) {
        if (isScrolling) return false;
        if($(this).hasClass("registered")){
            v_news[$(this).parent().index()]['flag'] = true
            v_news[$(this).parent().index()]['enrollStatus'] = v_news[$(this).parent().index()]['joinType'];
            if($(this).hasClass("calendarAdded")){
                v_news[$(this).parent().index()]['isSetReminder'] = "Y";
                $(this).removeClass("calendarAdded");
            }
            $(this).removeClass("registered");
        }
        // Nick disable click event for scrolling end
        var _activity = v_news[$(this).parent().index()];
        var _activityFlag = _activity['flag'];
        if(!_activityFlag){
             var questioniInfos = null;
            net.post('questionnaire/searchQuestionList', {
                'questionnaire_id': _activity.id
            }, function(error){
            }, function(response){
                if (response.code != 0) {
                    dia.alert('Confirmation', response.msg, ['OK'], function(title) {
                    });
                }
                else{
                    questioniInfos = response.data.questions;
                }
            },{async:false});
            if(questioniInfos && questioniInfos.length > 0){
                questionnaires.from('#newsroom');
                var info ={'acvtivitie':_activity,'question_infos':questioniInfos};
                questionnaires.setAcvtivities(info);
                $.mobile.newChangePage('#questionnaires_activity',{ transition: "slide",reverse: false, changeHash:false});
            }
            else{
                activityRegister.from('#newsroom');
                activityRegister.setAcvtivities(_activity);
                $.mobile.newChangePage('#activityRegister', { transition: "slide", reverse: false, changeHash:false});
            }
        }else{
            if(_activityFlag=='activity.deadTime'){
                dia.alert("Confirmation","You are too late! The registration of the activity is already closed.", ['OK'], function () {
                    return false;
                });
            }else if(_activityFlag=='activity.limitNum'){
                dia.alert("Confirmation","Sorry but your registration cannot be processed now as the activity has reached its maximum capacity.", ['OK'], function () {
                    return false;
                });
            }else if(_activityFlag=='activity.appIsTwo'){
                dia.alert("Confirmation","Looks like you have already registered this activity!", ['OK'], function () {
                    return false;
                });
            }else{
                dia.alert("Confirmation","Looks like have other issues. please contact #red help center!", ['OK'], function () {
                    return false;
                });
            }
        }
    }).on('click', '#newsroom_nowSurvey', function(evt) {
        if (isScrolling) return false;
        var _survey = v_news[$(this).parent().index()];
        if($(this).hasClass("registered")){
            _survey['regFlag'] = "true";
            $(this).removeClass("registered");
        }
        var _delineFlag = _survey['flag'];
        var _surveyFlag = _survey['regFlag'];
        if(_surveyFlag == "false"){
            if(_delineFlag=='survey.deadTime'){
                dia.alert("Oops","You are a bit late! The survey is already closed.", ['OK'], function () {
                });
                return false;
            }
            var questioniInfos = null;
            var surveyInfo = null;
                net.post('survey/getSurveyDetial', {
                    'survey_id': _survey.survey_id,
                    'appOrPCFlag':'APP',
                    'userId' :q['user'].userId
                }, function(error){
                }, function(response){
                    if (response.code != 0) {
                        dia.alert('Confirmation', response.msg, ['OK'], function(title) {
                        });
                    }
                    else{
                        surveyInfo = response.data.survey;
                        questioniInfos = response.data.survey.questions;
                    }
                },{async:false});
                if(questioniInfos && questioniInfos.length > 0){
                    surveyQuestionnaires.from('#newsroom');
                    surveyInfo.frompage = "#newsroom";
                    surveyInfo.backpage = "#newsroom";
                    var info ={'survey':surveyInfo,'question_infos':questioniInfos};
                    surveyQuestionnaires.setAcvtivities(info);
                    $.mobile.newChangePage('#questionnaires_survey',{ transition: "slide",reverse: false, changeHash:false});
                }
        }
        else{
            _survey.currentStatus = "complete";
            _survey.frompage = "#newsroom";
            surveyConfirm.showConfirmSurvey(_survey);
            surveyConfirm.backPage("#newsroom");
            $.mobile.newChangePage('#surveyConfirm', { transition: "slide", reverse: false, changeHash:false});
        }
    });

    $("#newsroom").on( "pagecreate", function() {
        $( "body > [data-role='panel']" ).panel();
        $( "body > [data-role='panel'] [data-role='listview']" ).listview();
    });

    $("#newsroom").on( "pagebeforeshow", function() {
        if (window.shouldPageRefresh.newsroom) {
            $("#newsroom_listview_news").empty();
            initPageLoading("news_wrapper");
        }
        var postData = {};
        var pageId = $("#newsroom").attr("pageId"); 
        if(pageId == "newsroom"){
            postData['paramKey'] = "news";
        }
        else if(pageId == "activities"){
            postData['paramKey'] = "activity";
        } 
        else if(pageId == "video"){
            postData['paramKey'] = "videoNews";
        }
        else if(pageId == "talentShow"){
            postData['paramKey'] = "news";
        }
        net.post('param/getParamByKey', postData, function(error){
            },
            function(response){
                if (response.code != 0) {
                }
                else {
                    showeye = response.data.param.param_value;
                }
            },{loading:false});
    });
    var toDetailPage = function(data){
            $("#video_detailed").page();
            var pageId = $("#newsroom").attr("pageId"); 
            $('#video_detailed_listview').empty();
            $('#video_listview_comments').empty();
            videodetail.from('#newsroom');  
            data.pageId = pageId;
            videodetail.showDetailWithNew(data);
            videodetail.showCommentsContent();
            initPageLoading("wrapper_comments");
            $.mobile.newChangePage("#video_detailed",{ transition: "slide",reverse: false,changeHash: false});
    }
    // 展示的时候请求新闻
    var getTagName = function(tagname){
        var html_tags = "";
        if (tagname == 'Communications')
            html_tags = '\<div class="filter_tags" style="background-color: rgb(77, 134, 176);">COMMS</div>';
        if (tagname == 'Corporate Sustainability')
            html_tags = '\<div class="filter_tags" style="background-color: rgb(137, 217, 78);">CS</div>';
        if (tagname == 'Finance')
            html_tags = '\<div class="filter_tags" style="background-color: rgb(219, 218, 0);">FIN</div>';
        if (tagname == 'Trade Union')
            html_tags = '\<div class="filter_tags" style="background-color: rgb(147, 182, 164);">GTU</div>';
        if (tagname == 'Human Resources')
            html_tags = '\<div class="filter_tags" style="background-color: rgb(230, 170, 0);">HR</div>';
        if (tagname == 'Q&P')
            html_tags = '\<div class="filter_tags" style="background-color: rgb(76, 176, 170);">Q&P</div>';
        if (tagname == 'Center Operations')
            html_tags = '\<div class="filter_tags" style="background-color: rgb(138, 116, 122)">OPS</div>';
        if (tagname == 'Technical Development')
            html_tags = '\<div class="filter_tags" style="background-color: rgb(121, 110, 172);">TD</div>';
        if (tagname == 'NOW')
            html_tags = '\<div class="filter_tags" style="background-color: #db0011;">NOW</div>';
        if (tagname == 'Talent Show')
            html_tags = '\<div class="filter_tags" style="background-color: #a3bdad;">TALENT SHOW</div>';
        if (tagname == '#red')
            html_tags = '\<div class="filter_tags" style="background-color: #f26647;">#red</div>';
        if (tagname == 'GSC')
            html_tags += '\<div class="filter_tags" style="background-color: #e6b012;">GSC</div>  ';
        return html_tags;
    }
    var getFiterInfo = function(filterList){
        var filterArr = [];
        $.each(filterList,function(index,filterInfo){
            var filterHtml = '\<li style="padding: 0px;height: 40px;b"><div class="ui-grid-b" style="height: 40px;line-height: 40px">\
            <div class="ui-block-a" style="width: 17%;height: auto;margin-top: 13px;overflow: auto">\
            '+getTagName(filterInfo.name)+'\</div><div class="ui-block-b" style="width: 70%;height: auto;margin: auto;">\
            <div style="font-family: Arial;font-size: 14px;margin-left: 10px">'+filterInfo.name+'\</div></div><div class="ui-block-c fRight" style="width: 13%;height: auto;margin-top: 0px;">\
            <div name="sbox" class="nor" alt="'+filterInfo.name+'"\></div></div></div></li>';
            filterArr.push(filterHtml);
        }); 
        $("#newsFilter_ul").html('\<li style="padding: 0px;height: 40px;"><div class="ui-grid-a" style="height: 40px;line-height: 40px">' +
            '\<div class="ui-block-a" style="font-family: Arial;font-size: 14px;width: 87%;height: auto;margin: auto;padding-left: 18%">All' +
            '\</div><div class="ui-block-b" style="width: 13%;height: auto;margin-top: 0px;"><div id="all_check" name="sbox2" class="nor">' +
            '\</div></div></div></li>'+filterArr.join(""));
    };

    function pageInitShow(){
        if($("#newsroom").hasClass("newsroom")){
                $("#newsroom_header_title").html("Newsroom");
                $("#activities_calendar").hide();
                $("#newsroom_btn_filter").show();
                $("#new_search").show(); 
        } 
        else if($("#newsroom").hasClass("activities")){
            $("#newsroom_header_title").html("Activities");
            $("#activities_calendar").show();
            $("#newsroom_btn_filter").show();
            $("#new_search").hide(); 
        } 
        else if($("#newsroom").hasClass("video")){
            $("#newsroom_header_title").html("HSBC NOW");
            $("#activities_calendar").hide();
            $("#newsroom_btn_filter").hide();
            $("#new_search").show(); 
        } 
        else if($("#newsroom").hasClass("talentShow")){
            $("#newsroom_header_title").html("Talent Show");
            $("#activities_calendar").hide();
            $("#newsroom_btn_filter").hide();
            $("#new_search").show(); 
        }  
    }
    function tagInitShow(){
        var postData = {};
        postData['userId'] = q['user'].userId;
        net.post('user/getTagsByDeptId', postData, function (error) {
        },
        function (response) {
            if (response.code != 0) {
            }
            else {
                getFiterInfo(response.data.list);
            }
        },{loading:false});
        localStorage['selected_tags']='';
        $('#newsroom_btn_filter').removeClass('filterOn').addClass('filter');
    }
    $("#newsroom").on( "pagebeforshow", function( event ) {
        $('div[id=newsroom_top]').hide();
         pagebeforeshow();  
    }); 

    $("#newsroom").on( "pageshow", function( event ) {
        disableClickEvent(true); 
        window.setBodyOverflow($(document.body));
        $('#news_content').css('height',($(window).height()-44));
        displayFilter(); 
        if (window.shouldPageRefresh.newsroom) { 
            getNews(true);
             if($("#newsFilter_ul li").size() == 0){
                 tagInitShow();
             }
        }  
        window.historyView = [];
    });
    function stopEventPropagation(event) {
        event.stopPropagation();
    }

    function initPageLoading(wrapper) {
        var $wrapper = $("#" + wrapper),
            $pullDownEl = $wrapper.find("#pullDown"),
            $pullUpEl = $wrapper.find("#pullUp");
        $pullUpEl.hide();
        var $pullDownLabel = $pullDownEl.find(".pullDownLabel");
        $wrapper.find(".scroller").css(window.getVendorStyle("transform"), "translate(0, 0)");
        $pullDownEl.css("margin-top","10px").attr("class", "loading");
        $pullDownLabel.text("Loading...");
    }

    function disableClickEvent(addListener) {
        var $disabledBody = $("body.disabled");
        if ($disabledBody.length > 0) {
            if (addListener) {
                $disabledBody[0].addEventListener("click", stopEventPropagation, true);
            } else {
                $disabledBody[0].removeEventListener("click", stopEventPropagation, true);
                $disabledBody.removeClass("disabled");
            }
        }
    }
    //新闻搜索
    $('#new_search').off('click');
    $('#new_search').on('click', function() {        
        // 隐藏菜单和过滤，搜索
        $('#newsroom_header_title').css('display', 'none'); // block
        $('#newsroom_btn_menu').css('display', 'none'); // inline
        $('#newsroom_header_buttons').css('display', 'none'); //block
        // 展示搜索
        var li = '\<div>\
                <form id="newsroom_header_searchbar_form" style="width: 75%;float: left;margin: auto 0px auto 10px" action="javascript:void(0);"><input id="newsroom_header_searchbar" type="text" placeholder="Search" autocomplete="off" autocapitalize="off" autocorrect="off" style="margin-top:7px;height: 28px;width: 100%;border: solid 0px rgb(255,0,0);"/></form>\
                <input id="newsroom_header_cancel" style="width: 50px;float: left;padding: 0px;margin:12px 0px 9px 10px;background-color: rgba(0,0,0,0);border: none;color: white;font-size: 14px;" type="button" value="Cancel" />\
            </div>';
        $('#newsroom_header').append(li);
        $('#newsroom_header_cancel').off('click')
            .on('click', function() {
            $('#newsroom_header_searchbar').remove();
            $('#newsroom_header_cancel').remove();
            $('#newsroom_header_searchbar_form').remove();
            $('#newsroom_header_title').css('display', 'block');
            $('#newsroom_btn_menu').css('display', 'inline');
            $('#newsroom_header_buttons').css('display', 'block'); 
            initPageLoading("news_wrapper");
            getNews(true); 
        });
 
        $('#newsroom_header_searchbar').off('keyup')
        .on('keyup', function(evt) {
            if (evt.keyCode == 13) {
                $('#newsroom_header_searchbar').blur(); 
                initPageLoading("news_wrapper");
                getNews(true); 
            }
        });
        $('#newsroom_header_searchbar').focus();
    });

    function compatibility() {
        /* Logon */
        $('#newsroom_header_title').parent()
            .css('display', 'block')
            .css('postion', 'relative');

        $('#newsroom_header_title').css('postion', 'absulute')
            .css('width', '180px')
            .css('height','20px')
            .css('margin', '8px auto auto auto');
    }

    $(document).ready(function() {
        // 兼容其他浏览器
        compatibility();

        $('.ui-panel-inner').css({'padding':'0px'});
        $('div[id=newsroom_top]').on('click',function() {
            $('div[id=newsroom_top]').fadeOut();
            $("#news_wrapper").find(".scroller").css("-webkit-transform", "translate(0px, -50px)");

        });
    }); 
    return {
        templateNews : function() {
            getNews(true,"pageInit");
        }
    }
});